package com.jreque.queue;

import java.util.*;
import com.jreque.queue.*;
import java.lang.*;

/**
 * Task structure.
 */
public class Task {
    /**
     * A queue name to which task should be enqueued.
     */
    private String queueName;

    /**
     * Invocation data for execution of task.
     */
    private ITaskInvocation invocation;

    /**
     * Arguments that should be passed to invocation.
     */
    private ArrayList arguments;

    /**
     * A date of invocation. Task will not be executed before it, but there is no warranty it will be executed immediatelly after this date is hit.
     */
    private Date executeAfter;

    public Task(String queueName, ITaskInvocation invocation, ArrayList arguments, Date executeAfter) {
        if(queueName == null || queueName.isEmpty()) throw new IllegalArgumentException("Queue name not specified");
        if(invocation == null) throw new IllegalArgumentException("Invocation not specified");
        this.queueName = queueName;
        this.invocation = invocation;
        this.arguments = arguments;
        this.executeAfter = executeAfter;
    }

    /**
     * Invokes task execution.
     */
    public void invoke() {
        invocation.invoke(arguments);
    }

    /**
     * @return the queueName
     */
    public String getQueueName() {
        return queueName;
    }

    /**
     * @param queueName the queueName to set
     */
    public void setQueueName(String queueName) {
        this.queueName = queueName;
    }

    /**
     * @return the invocation
     */
    public ITaskInvocation getInvocation() {
        return invocation;
    }

    /**
     * @param invocation the invocation to set
     */
    public void setInvocation(ITaskInvocation invocation) {
        this.invocation = invocation;
    }

    /**
     * @return the arguments
     */
    public ArrayList getArguments() {
        return arguments;
    }

    /**
     * @param arguments the arguments to set
     */
    public void setArguments(ArrayList arguments) {
        this.arguments = arguments;
    }

    /**
     * @return the executeAfter
     */
    public Date getExecuteAfter() {
        return executeAfter;
    }

    /**
     * @param executeAfter the executeAfter to set
     */
    public void setExecuteAfter(Date executeAfter) {
        this.executeAfter = executeAfter;
    }
}

